/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            labelManageInfo: {
                labels: [],
                total: 0,
                records: 1,
                moreCondition: false,
                labelId: '',
                conditions: {
                    labelName: '',
                    domains: [],
                    domain: '',
                    labelCd: 'C',
                    shopId: ''
                }
            }
        },
        _initMethod: function () {
            $that.labelManageInfo.conditions.shopId = vc.getCurrentCommunity().shopId;
            $that._listLabels(DEFAULT_PAGE, DEFAULT_ROWS);
            vc.getDict('s_label', "domain", function (_data) {
                $that.labelManageInfo.domains = _data;
            });
        },
        _initEvent: function () {
            vc.on('labelManage', 'listLabel', function (_param) {
                $that._listLabels(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listLabels(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listLabels: function (_page, _rows) {
                $that.labelManageInfo.conditions.page = _page;
                $that.labelManageInfo.conditions.row = _rows;
                var param = {
                    params: $that.labelManageInfo.conditions
                };
                param.params.labelName = param.params.labelName.trim();
                //发送get请求
                vc.http.apiGet('/label/queryLabel',
                    param,
                    function (json, res) {
                        var _labelManageInfo = JSON.parse(json);
                        $that.labelManageInfo.total = _labelManageInfo.total;
                        $that.labelManageInfo.records = _labelManageInfo.records;
                        $that.labelManageInfo.labels = _labelManageInfo.data;
                        vc.emit('pagination', 'init', {
                            total: $that.labelManageInfo.records,
                            dataCount: $that.labelManageInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddLabelModal: function () {
                vc.emit('addLabel', 'openAddLabelModal', {});
            },
            _openEditLabelModel: function (_label) {
                vc.emit('editLabel', 'openEditLabelModal', _label);
            },
            _openDeleteLabelModel: function (_label) {
                vc.emit('deleteLabel', 'openDeleteLabelModal', _label);
            },
            //查询
            _queryLabelMethod: function () {
                $that._listLabels(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetLabelMethod: function () {
                $that.labelManageInfo.conditions.labelName = "";
                $that.labelManageInfo.conditions.domain = "";
                $that._listLabels(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.labelManageInfo.moreCondition) {
                    $that.labelManageInfo.moreCondition = false;
                } else {
                    $that.labelManageInfo.moreCondition = true;
                }
            }
        }
    });
})(window.vc);
